/*
 * GUIPrincipal.java
 *
 * Created on 15/05/2011, 10:32:25
 */

package gui;

import connection.Conexao;
import dao.DAOOperador;
import dao.ResultSetComboBox;
import javax.swing.*;
import javax.swing.JOptionPane;
import model.KeyValue;
import model.Utils;
import model.Operador;
import model.Relatorios;

/**
 * Interface principal do programa
 * @author Janio Luiz Antunes
 * @author Marcel Vinicius Kohls
 * @see http://code.google.com/p/sysdesk-java/
 *
 */
public class GUIPrincipal extends javax.swing.JFrame {

    private DAOOperador operadorDAO = new DAOOperador();
    private Utils util = new Utils();
    Relatorios novoRelatorio = new Relatorios();
  
    /** 
     * Inicializa o form principal GUIPrincipal
     */
    public GUIPrincipal() {
        initComponents();
        initConfiguracoes();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree();
        jPanel1 = new javax.swing.JPanel();
        jlbInfoConexao = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jcbOperador = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jtfFuncaoOperador = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jlbImagemOperador = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jmnOpcoes = new javax.swing.JMenu();
        jmiCategorias = new javax.swing.JMenuItem();
        jmiClientes = new javax.swing.JMenuItem();
        jmiOperadores = new javax.swing.JMenuItem();
        jmiUsuarios = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jmiSair = new javax.swing.JMenuItem();
        jmnChamados = new javax.swing.JMenu();
        jmiIncluirChamado = new javax.swing.JMenuItem();
        jmiBuscarChamado = new javax.swing.JMenuItem();
        jmRelatorios = new javax.swing.JMenu();
        jmChamPorCategoria = new javax.swing.JMenuItem();
        jmChamPorCliente = new javax.swing.JMenuItem();
        jmChamPorCodigo = new javax.swing.JMenuItem();
        jmChamPorOperador = new javax.swing.JMenuItem();
        jmnSobre = new javax.swing.JMenu();

        jScrollPane1.setViewportView(jTree1);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SysDesk - Gerenciador de chamados");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentShown(java.awt.event.ComponentEvent evt) {
                formComponentShown(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jlbInfoConexao.setText("...");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlbInfoConexao, javax.swing.GroupLayout.DEFAULT_SIZE, 636, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jlbInfoConexao, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
        );

        jPanel2.setBackground(new java.awt.Color(128, 0, 128));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/sysdesk-logo.PNG"))); // NOI18N

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/sysdesk-icon.png"))); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel2)
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addContainerGap(350, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jLabel2))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Operador atual", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        jcbOperador.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcbOperador.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcbOperadorItemStateChanged(evt);
            }
        });

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel3.setText("Operador:");

        jtfFuncaoOperador.setEditable(false);

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText("Função:");

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jlbImagemOperador.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jlbImagemOperador, javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE)
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jlbImagemOperador, javax.swing.GroupLayout.DEFAULT_SIZE, 62, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(48, 48, 48)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtfFuncaoOperador, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE)
                    .addComponent(jcbOperador, 0, 217, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jcbOperador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtfFuncaoOperador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 145, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 124, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 633, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 32, Short.MAX_VALUE)
        );

        jmnOpcoes.setText("Opções");

        jmiCategorias.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/category.png"))); // NOI18N
        jmiCategorias.setText("Categorias");
        jmiCategorias.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiCategoriasActionPerformed(evt);
            }
        });
        jmnOpcoes.add(jmiCategorias);

        jmiClientes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/clientes.png"))); // NOI18N
        jmiClientes.setText("Clientes");
        jmiClientes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiClientesActionPerformed(evt);
            }
        });
        jmnOpcoes.add(jmiClientes);

        jmiOperadores.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/operadores.png"))); // NOI18N
        jmiOperadores.setText("Operadores");
        jmiOperadores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiOperadoresActionPerformed(evt);
            }
        });
        jmnOpcoes.add(jmiOperadores);

        jmiUsuarios.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/customers.png"))); // NOI18N
        jmiUsuarios.setText("Usuários");
        jmiUsuarios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiUsuariosActionPerformed(evt);
            }
        });
        jmnOpcoes.add(jmiUsuarios);
        jmnOpcoes.add(jSeparator1);

        jmiSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/sign-out.png"))); // NOI18N
        jmiSair.setText("Sair");
        jmiSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiSairActionPerformed(evt);
            }
        });
        jmnOpcoes.add(jmiSair);

        jMenuBar1.add(jmnOpcoes);

        jmnChamados.setText("Chamados");

        jmiIncluirChamado.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/edit.png"))); // NOI18N
        jmiIncluirChamado.setText("Incluir");
        jmiIncluirChamado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiIncluirChamadoActionPerformed(evt);
            }
        });
        jmnChamados.add(jmiIncluirChamado);

        jmiBuscarChamado.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/search.png"))); // NOI18N
        jmiBuscarChamado.setText("Buscar");
        jmiBuscarChamado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmiBuscarChamadoActionPerformed(evt);
            }
        });
        jmnChamados.add(jmiBuscarChamado);

        jMenuBar1.add(jmnChamados);

        jmRelatorios.setText("Relatórios");

        jmChamPorCategoria.setText("Chamados por categoria");
        jmChamPorCategoria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmChamPorCategoriaActionPerformed(evt);
            }
        });
        jmRelatorios.add(jmChamPorCategoria);

        jmChamPorCliente.setText("Chamados por cliente");
        jmChamPorCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmChamPorClienteActionPerformed(evt);
            }
        });
        jmRelatorios.add(jmChamPorCliente);

        jmChamPorCodigo.setText("Chamado por código");
        jmChamPorCodigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmChamPorCodigoActionPerformed(evt);
            }
        });
        jmRelatorios.add(jmChamPorCodigo);

        jmChamPorOperador.setText("Chamado por operador");
        jmChamPorOperador.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jmChamPorOperadorActionPerformed(evt);
            }
        });
        jmRelatorios.add(jmChamPorOperador);

        jMenuBar1.add(jmRelatorios);

        jmnSobre.setText("Sobre");
        jmnSobre.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jmnSobreMouseClicked(evt);
            }
        });
        jMenuBar1.add(jmnSobre);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Inicializa dados básicos do sistema
     */
    private void initConfiguracoes(){
        // conecta ao banco
        try {
            jlbInfoConexao.setText("Conectando ao servidor...");
            Conexao.loadConfigFromIni("sysdesk.ini");
            if (Conexao.conectar() == true) {
                jlbInfoConexao.setText("Conectado.");
                jlbInfoConexao.setIcon(new ImageIcon(ClassLoader.getSystemResource("images/bullet_green.png")));
            }
        } catch (Exception e) {
            System.out.println("initConfiguracoes:Banco: "+e.getMessage());
        }

        // carrega dados da caixa de selecionar operador
        try {
            jcbOperador.setModel(new ResultSetComboBox(operadorDAO.getListaOperadores(operadorDAO.OPE_NONE, ""), "ope_nome", "ope_codigo", 0).getModel());
        } catch (Exception e) {
            System.out.println("initConfiguracoes:ComboBoxOperadores: "+e.getMessage());
        }

        jtfFuncaoOperador.setText("");
       

        jlbImagemOperador.setIcon(new ImageIcon(ClassLoader.getSystemResource("images/operador_indefinido.png")));
    }

    /**
     *
     * Fecha a aplicação se não conseguiu efetuar a conexão com o banco
     */
    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
       
        if (Conexao.isConnected() == false) {
            JOptionPane.showMessageDialog(null, "Erro ao efetuar a conexão com o banco. \n\n Para mais informações:\n http://code.google.com/p/sysdesk-java/");
            this.dispose();
        }
    }//GEN-LAST:event_formWindowOpened

    /**
     *
     * Quando a janela estiver sendo fechada, desconecta a conexão do banco
     */
    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        if (Conexao.isConnected() == true) {
            try {
                jlbInfoConexao.setText("Desconectando do servidor...");
                Conexao.desconectar();
            } finally {
                jlbInfoConexao.setText("Desconectado.");
            }

            jlbInfoConexao.setIcon(new ImageIcon(ClassLoader.getSystemResource("images/bullet_red.png")));
        }
    }//GEN-LAST:event_formWindowClosing

    /**
     *
     * Fecha esta tela
     */
    private void jmiSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiSairActionPerformed
        this.dispose();
    }//GEN-LAST:event_jmiSairActionPerformed

    /**
     *
     * Quando a tela for aberta, define sua localização
     */
    private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown
        this.setLocation(util.getTelaColunaCentro(this), util.getTelaLinhaCentro(this));
    }//GEN-LAST:event_formComponentShown

    /**
     *
     * Abre a tela "Sobre"
     */
    private void jmnSobreMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jmnSobreMouseClicked
        GUISobre sobre = new GUISobre();
        sobre.setLocation(util.getTelaColunaCentro(sobre), util.getTelaLinhaCentro(sobre));
        sobre.setVisible(true);
    }//GEN-LAST:event_jmnSobreMouseClicked

    /**
     *
     * Abre a interface que lista os usuários
     */
    private void jmiUsuariosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiUsuariosActionPerformed
        GUIUsuarios guiUsuarios = new GUIUsuarios();
        guiUsuarios.setLocation(util.getTelaColunaMaxima(guiUsuarios), util.getTelaLinhaMaxima(guiUsuarios));
        guiUsuarios.setVisible(true);
    }//GEN-LAST:event_jmiUsuariosActionPerformed

    /**
     *
     * Abre a interface que lista os operadores
     */
    private void jmiOperadoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiOperadoresActionPerformed
        GUIOperadores guiOperadores = new GUIOperadores();
        guiOperadores.setLocation(util.getTelaColunaCentro(guiOperadores), util.getTelaLinhaCentro(guiOperadores));
        guiOperadores.setVisible(true);
    }//GEN-LAST:event_jmiOperadoresActionPerformed

    /**
     *
     * Abre a interface que lista as categorias
     */
    private void jmiCategoriasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiCategoriasActionPerformed
        GUICategorias guiCategorias = new GUICategorias();
        guiCategorias.setLocation(util.getTelaColunaMaxima(guiCategorias), util.getTelaLinhaMaxima(guiCategorias));
        guiCategorias.setVisible(true);
    }//GEN-LAST:event_jmiCategoriasActionPerformed

    /**
     *
     * Abre a interface que lista os clientes
     */
    private void jmiClientesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiClientesActionPerformed
        GUITabelaClientes tabelaClientes = new GUITabelaClientes();
        tabelaClientes.setVisible(true);
    }//GEN-LAST:event_jmiClientesActionPerformed

    /**
     *
     * Carrega os operadores no comboBox da tela principal
     */
    private void jcbOperadorItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcbOperadorItemStateChanged
        try {
            Operador operadorSelecionado = (Operador) operadorDAO.getOperadorPorCodigo((Integer)(((KeyValue) jcbOperador.getSelectedItem()).getValue()));
            jtfFuncaoOperador.setText(operadorSelecionado.getDescFuncao());
           
            if (operadorSelecionado.getCodFuncao() == operadorDAO.OPE_ATENDENTE) {
                jlbImagemOperador.setIcon(new ImageIcon(ClassLoader.getSystemResource("images/operador_atendente.png")));
            } else if (operadorSelecionado.getCodFuncao() == operadorDAO.OPE_ANALISTA) {
                jlbImagemOperador.setIcon(new ImageIcon(ClassLoader.getSystemResource("images/operador_analista.png")));
            } else {
                jlbImagemOperador.setIcon(new ImageIcon(ClassLoader.getSystemResource("images/operador_indefinido.png")));
            }

        } catch (Exception e) {

        }

    }//GEN-LAST:event_jcbOperadorItemStateChanged

    /**
     *
     * apenas chama tela de incluir chamado se algum operador estiver selecionado
     */
    private void jmiIncluirChamadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiIncluirChamadoActionPerformed
        
        if (jcbOperador.getSelectedIndex() >= 0) {
            GUIChamadosIncluir guiChamadosIncluir = new GUIChamadosIncluir();
            guiChamadosIncluir.setLocation(util.getTelaColunaCentro(guiChamadosIncluir), util.getTelaLinhaCentro(guiChamadosIncluir));
            guiChamadosIncluir.setCodOperador((Integer)(((KeyValue) jcbOperador.getSelectedItem()).getValue()));
            guiChamadosIncluir.setVisible(true);
        } else {
            JOptionPane.showMessageDialog(null, "Antes de manipular chamados selecione um operador na tela principal.");
        }
    }//GEN-LAST:event_jmiIncluirChamadoActionPerformed

    /**
     *
     * Abre a janela para busca de chamados já cadastrados
     */
    private void jmiBuscarChamadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiBuscarChamadoActionPerformed
            GUIChamadosBuscar guiBuscarChamados = new GUIChamadosBuscar();
            guiBuscarChamados.setLocation(util.getTelaColunaCentro(guiBuscarChamados), util.getTelaLinhaCentro(guiBuscarChamados));
            guiBuscarChamados.setVisible(true);
    }//GEN-LAST:event_jmiBuscarChamadoActionPerformed

    /**
     *
     * Evento que carrega o relatório de chamados ordenado por categoria
     */
    private void jmChamPorCategoriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmChamPorCategoriaActionPerformed
        novoRelatorio.gerarNovoRelatorio("src/relatorios/chamado_categoria.jasper");
    }//GEN-LAST:event_jmChamPorCategoriaActionPerformed

    /**
     *
     * Evento que carrega o relatório de chamados ordenado por cliente
     */
    private void jmChamPorClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmChamPorClienteActionPerformed
        novoRelatorio.gerarNovoRelatorio("src/relatorios/chamado_cliente.jasper");
    }//GEN-LAST:event_jmChamPorClienteActionPerformed

    /**
     *
     * Evento que carrega o relatório de chamados ordenado por código
     */
    private void jmChamPorCodigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmChamPorCodigoActionPerformed
        novoRelatorio.gerarNovoRelatorio("src/relatorios/chamado_codigo.jasper");
    }//GEN-LAST:event_jmChamPorCodigoActionPerformed

    /**
     *
     * Evento que carrega o relatório de chamados ordenado por operador
     */
    private void jmChamPorOperadorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmChamPorOperadorActionPerformed
        novoRelatorio.gerarNovoRelatorio("src/relatorios/chamado_operador.jasper");
    }//GEN-LAST:event_jmChamPorOperadorActionPerformed


    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GUIPrincipal().setVisible(true);
                
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JTree jTree1;
    private javax.swing.JComboBox jcbOperador;
    private javax.swing.JLabel jlbImagemOperador;
    private javax.swing.JLabel jlbInfoConexao;
    private javax.swing.JMenuItem jmChamPorCategoria;
    private javax.swing.JMenuItem jmChamPorCliente;
    private javax.swing.JMenuItem jmChamPorCodigo;
    private javax.swing.JMenuItem jmChamPorOperador;
    private javax.swing.JMenu jmRelatorios;
    private javax.swing.JMenuItem jmiBuscarChamado;
    private javax.swing.JMenuItem jmiCategorias;
    private javax.swing.JMenuItem jmiClientes;
    private javax.swing.JMenuItem jmiIncluirChamado;
    private javax.swing.JMenuItem jmiOperadores;
    private javax.swing.JMenuItem jmiSair;
    private javax.swing.JMenuItem jmiUsuarios;
    private javax.swing.JMenu jmnChamados;
    private javax.swing.JMenu jmnOpcoes;
    private javax.swing.JMenu jmnSobre;
    private javax.swing.JTextField jtfFuncaoOperador;
    // End of variables declaration//GEN-END:variables

}
